package com.fx.asds.controller;

import com.fx.asds.domain.Asds;
import com.fx.asds.service.AsdsService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 行政区划Controller
 *
 * @author fxiao
 * @date 2021-04-12
 */
@RestController
@RequestMapping("/fx/asds")
public class AsdsController extends BaseController
{
    @Autowired
    private AsdsService asdsService;

    /**
     * 查询行政区划列表
     */
    @PreAuthorize("@ss.hasPermi('fx:asds:list')")
    @GetMapping("/list")
    public AjaxResult list(Asds asds)
    {
        List<Asds> list = asdsService.selectAsdsList(asds);
        return AjaxResult.success(list);
    }

    /**
     * 导出行政区划列表
     */
    @PreAuthorize("@ss.hasPermi('fx:asds:export')")
    @Log(title = "行政区划", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Asds asds)
    {
        List<Asds> list = asdsService.selectAsdsList(asds);
        ExcelUtil<Asds> util = new ExcelUtil<Asds>(Asds.class);
        return util.exportExcel(list, "asds");
    }

    /**
     * 获取行政区划详细信息
     */
    @PreAuthorize("@ss.hasPermi('fx:asds:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(asdsService.selectAsdsById(id));
    }

    /**
     * 新增行政区划
     */
    @PreAuthorize("@ss.hasPermi('fx:asds:add')")
    @Log(title = "行政区划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Asds asds)
    {
        return toAjax(asdsService.insertAsds(asds));
    }

    /**
     * 修改行政区划
     */
    @PreAuthorize("@ss.hasPermi('fx:asds:edit')")
    @Log(title = "行政区划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Asds asds)
    {
        return toAjax(asdsService.updateAsds(asds));
    }

    /**
     * 删除行政区划
     */
    @PreAuthorize("@ss.hasPermi('fx:asds:remove')")
    @Log(title = "行政区划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(asdsService.deleteAsdsByIds(ids));
    }

    /**
     * 获取部门下拉树列表
     */
    @GetMapping("/treeselect")
    public AjaxResult treeselect(SysDept dept)
    {
        return AjaxResult.success(asdsService.buildTree());
    }
}
